package pers.kevin.fsm.server;

import pers.kevin.fsm.factory.OperationFactory;
import pers.kevin.fsm.operation.Operation;


public class CommandOperator {
	
	private String command;
	

	public String getCommand() {
	    return command;
	}


        public void setCommand(String command) {
            this.command = command;
        }



        public CommandOperator(String command) {
            super();
            this.command = command;
	}


        /**
	 * execute command
	 * @return
	 */
	public String execute() {
	    String operate = "";
	    if(this.command != null){
	        if(this.command.trim().contains(" ")){
	            String[] split = this.command.trim().split("\\s+");
	            operate = split[0];
	        }else{
	            operate = this.command.trim();
	        }
	    }
	    Operation operation = OperationFactory.createOperate(operate);
	    if(operation != null){
	        operation.setCommand(this.command);
	        return operation.getResult();
	    }else{
	        return "command not found.";
	    }
	}

}
